﻿@page "/CSharpBackParameter"
@using JavaDevToys.Rcl.Service
<MAlert Dismissible
        Type="AlertTypes.Error"
        @bind-Value="_alert">
    @errMsg
</MAlert>
<h3>属性生成</h3>
<MContainer Fluid>
    <MRow Align="@AlignTypes.Center">
        <MTextarea Clearable
                   ClearIcon="mdi-close-circle"
                   Label="复制表格内容到此"
                   @bind-Value="javaText">
        </MTextarea>
    </MRow>
    <MRow Align="@AlignTypes.Center">
        <MButton Color="primary" Class="mt-2  ml-9" OnClick="CreateJavaParameter">生成</MButton>
        <MButton Color="primary" Class="mt-2  ml-9" OnClick="CopyJavaParameter">复制结果</MButton>
    </MRow>
    <MRow Align="@AlignTypes.Center">
        <MTextarea Clearable
                   ClearIcon="mdi-close-circle"
                   Label="模型"
                   @bind-Value="JavaParameterResult">
        </MTextarea>
    </MRow>
</MContainer>
@code {
    private bool _alert = false;
    private string errMsg = string.Empty;
    private string javaText;
    private string JavaParameterResult;
    [Inject]
    public IParameterInfoParser parameterInfoParser { get; set; }
    [Inject]
    public IJavaCodeGenerator javaCodeGenerator { get; set; }
    [Inject]
    public IClipboardService clipboardService { get; set; }
    private void CreateJavaParameter()
    {
        if (string.IsNullOrWhiteSpace(javaText))
        {
            errMsg = "内容不能为空";
            _alert = true;
            return;
        }
        var parameterInfos = parameterInfoParser.ParseCSharp(javaText);
        JavaParameterResult = javaCodeGenerator.GenerateCSharpParameter(parameterInfos);
    }

    private void CopyJavaParameter()
    {
        clipboardService.SetTextAsync(JavaParameterResult);
    }
}
